package com.starbucks.opencase.function;

import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;

/**
 * 短信宝
 */
public class funDXB {
    public boolean sendCode(String phone,String code,int time){
        try{
            String content="【宠宝宝】您的验证码是"+code+"。有效时间60秒。如非本人操作，请忽略本短信。";
            String url="http://api.smsbao.com/sms?u=solitarywayfarer&p=1d8b21ba191c46f3864a26f747a38b1c&m="+phone
                    +"&c="+ URLEncoder.encode(content, StandardCharsets.UTF_8);
            HttpClient client=HttpClient.newHttpClient();
            HttpRequest request= HttpRequest.newBuilder()
                    .uri(new URI(url))
                    .timeout(Duration.ofSeconds(1))
                    .GET()
                    .build();
            HttpResponse<String> response=client.send(request, HttpResponse.BodyHandlers.ofString());
            String a= response.body();
            return a.equals("0");
        }catch (Exception e){
            return false;
        }
    }
}
